package com.ruoyi.lnb.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.lnb.domain.Communities;
import com.ruoyi.lnb.service.ICommunitiesService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 社区管理Controller
 * 
 * @author lnb
 * @date 2022-04-05
 */
@RestController
@RequestMapping("/lnb/communities")
public class CommunitiesController extends BaseController
{
    @Autowired
    private ICommunitiesService communitiesService;

    /**
     * 查询社区管理列表
     */
    @PreAuthorize("@ss.hasPermi('lnb:communities:list')")
    @GetMapping("/list")
    public TableDataInfo list(Communities communities)
    {
        startPage();
        List<Communities> list = communitiesService.selectCommunitiesList(communities);
        return getDataTable(list);
    }

    /**
     * 导出社区管理列表
     */
    @PreAuthorize("@ss.hasPermi('lnb:communities:export')")
    @Log(title = "社区管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Communities communities)
    {
        List<Communities> list = communitiesService.selectCommunitiesList(communities);
        ExcelUtil<Communities> util = new ExcelUtil<Communities>(Communities.class);
        util.exportExcel(response, list, "社区管理数据");
    }

    /**
     * 获取社区管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('lnb:communities:query')")
    @GetMapping(value = "/{ccid}")
    public AjaxResult getInfo(@PathVariable("ccid") Long ccid)
    {
        return AjaxResult.success(communitiesService.selectCommunitiesByCcid(ccid));
    }

    /**
     * 新增社区管理
     */
    @PreAuthorize("@ss.hasPermi('lnb:communities:add')")
    @Log(title = "社区管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Communities communities)
    {
        return toAjax(communitiesService.insertCommunities(communities));
    }

    /**
     * 修改社区管理
     */
    @PreAuthorize("@ss.hasPermi('lnb:communities:edit')")
    @Log(title = "社区管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Communities communities)
    {
        return toAjax(communitiesService.updateCommunities(communities));
    }

    /**
     * 删除社区管理
     */
    @PreAuthorize("@ss.hasPermi('lnb:communities:remove')")
    @Log(title = "社区管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ccids}")
    public AjaxResult remove(@PathVariable Long[] ccids)
    {
        return toAjax(communitiesService.deleteCommunitiesByCcids(ccids));
    }
}
